package ldh.im.fxgui.component;

import javafx.scene.web.WebView;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class WebViewPage {

    private static final Logger LOGGER = LoggerFactory.getLogger(WebViewPage.class);

    private String url;
    private ImStage newStage = null;

    public WebViewPage(String url) {
        this.url = url;

        initUi();
    }

    public void show() {
        newStage.show();
        newStage.getStage().toFront();
    }

    public void hide() {
        newStage.close();
    }

    private void initUi() {
        newStage = new ImStage(880, 500);
        newStage.setTitle(url);

        WebView webView = new WebView();
        webView.getEngine().load(url);

        newStage.setContent(webView);
        newStage.setOnCloseRequest(ee -> {
            LOGGER.debug("newStage do close event！");
        });
    }
}
